package cn.iocoder.yudao.module.member.dal.mysql.usercommission;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.member.dal.dataobject.usercommission.UserCommissionDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.member.controller.admin.usercommission.vo.*;
import org.apache.ibatis.annotations.Param;

/**
 * 佣金 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface UserCommissionMapper extends BaseMapperX<UserCommissionDO> {

    default PageResult<UserCommissionDO> selectPage(UserCommissionPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<UserCommissionDO>()
                .eqIfPresent(UserCommissionDO::getUserId, reqVO.getUserId())
                .eqIfPresent(UserCommissionDO::getInviterType, reqVO.getInviterType())
                .eqIfPresent(UserCommissionDO::getFirstInviteeUserId, reqVO.getFirstInviteeUserId())
                .eqIfPresent(UserCommissionDO::getSecondInviteeUserId, reqVO.getSecondInviteeUserId())
                .eqIfPresent(UserCommissionDO::getPayPackageOrderId, reqVO.getPayPackageOrderId())
                .eqIfPresent(UserCommissionDO::getRecharge, reqVO.getRecharge())
                .eqIfPresent(UserCommissionDO::getCommission, reqVO.getCommission())
                .betweenIfPresent(UserCommissionDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(UserCommissionDO::getId));
    }

    Integer totalCommissionByUserId(@Param("userId") Long userId);

    Integer firstTotalRechargeByUserId(@Param("userId") Long userId);

    Integer firstTotalRecharge(@Param("firstInviteeUserId") Long firstInviteeUserId);

    Integer secondTotalRecharge(@Param("firstInviteeUserId") Long firstInviteeUserId);

}